package com.dao.qsl;

import com.util.qsl.Dbutil;
import org.springframework.stereotype.Repository;

import javax.servlet.http.HttpServletRequest;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Map;

@Repository
public class AddBxDao {
      public Boolean add(HttpServletRequest request,String bxlr,String lxdh,String tpname ) {
	  Dbutil d=new Dbutil();

	  Connection c=null;

	  PreparedStatement pr=null;

	  //获取aid

//	  Map<String,Object> user = (Map<String,Object>)request.getSession().getAttribute("user");
//	  String aid = (String) user.get("aid");

//	  System.out.println("aid:"+aid);
	  try{

	        if(request.getSession().getAttribute("user")!=null){
		    //执行相应的操作 例如输出
		    Map<String,Object> user = (Map<String,Object>)request.getSession().getAttribute("user");
		    int aid = (int) user.get("aid");
		    c=d.getConnection();

	        /**
	         * 1业主id
	         * 2报修类容
	         * 3图片名称
	         *4联系电话
	         * */


	        String sql="INSERT into maintain VALUES(null,?,?,?,NOW(),'B',?,0)";


	       pr=c.prepareStatement(sql);

	        pr.setInt(1,aid);
	        pr.setString(2,bxlr);
	        pr.setString(3,tpname);
	        pr.setString(4,lxdh);

	        int i=pr.executeUpdate();

	        if(i>0){
		    return true;
	        }else {
		    return false;
	        }
	        }else {
		    System.out.println("aid为空");
	        }
	  }catch (Exception e){
	        e.printStackTrace();
	  }
	  return false;
      }
}
